<xsl:stylesheet version="1.1"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns="http://www.w3.org/2000/svg"
                xmlns:xlink="http://www.w3.org/1999/xlink"
                xmlns:random="http://exslt.org/random"
                exclude-result-prefixes="random">

  <xsl:output method="xml"/>
  
  <xsl:param name="radius">100</xsl:param>
  <xsl:param name="width" select="$radius * 4"/>
  <xsl:param name="height" select="$width"/>
  <xsl:param name="animationDuration">1</xsl:param>
  <xsl:param name="toAngle" select="360"/>
    
  <xsl:template match="/">
    
	<svg width="{$width}" height="{$height}" viewBox="{-$width div 2} {-$height div 2} {$width} {$height}">
	    <g>
		  	<text x="{$radius * 0.9}" y="-{$radius * 0.9}" font-family="Verdana" font-weight="bold" font-size="{$radius * 0.3}" fill="black" >2</text>
		  	<g>
				<xsl:apply-templates select="landmarks/phase"/>
					    
			  	<circle cx="0" cy="0" r="{$radius}" fill="white" stroke="black" stroke-width="5"  />
			  	<!-- 
		   		<animateTransform attributeName="transform" attributeType="XML"
		                    type="rotate" from="0" to="-720" dur="10" begin="0"
		                    additive="replace" fill="freeze"/>
		                     -->
		  	</g>
        </g>
	</svg>	  
  </xsl:template>
  
  <xsl:template match="phase">
  	<xsl:apply-templates select="building">
  		<xsl:with-param name="from" select="@from"/>
  		<xsl:with-param name="dur" select="@dur"/>
  	</xsl:apply-templates>
  </xsl:template>
  
  <xsl:template match="building">
  	<xsl:param name="from">0</xsl:param>
  	<xsl:param name="dur">1</xsl:param>
  	<xsl:param name="bldgheight" select="@height * $radius"/>
  	<xsl:param name="bldgwidth" select="@width * $radius"/>
  	<xsl:param name="popTime" select="$from + @time * $dur"/>
  	<xsl:param name="popDuration" select="@height"/>
  	
  	<xsl:variable name="z">
  		<xsl:choose>
  			<xsl:when test="@z">
  				<xsl:value-of select="@z"/>
  			</xsl:when>
  			<xsl:otherwise>0</xsl:otherwise>
  		</xsl:choose>
  	</xsl:variable>
  	
  	<xsl:variable name="popAdjust">
		<xsl:choose>
			<xsl:when test="@popAdjust">
				<xsl:value-of select="@popAdjust"/>
			</xsl:when>
			<xsl:otherwise>0</xsl:otherwise>
		</xsl:choose>
  	</xsl:variable>
  	<xsl:variable name="angle">
		<xsl:choose>
			<xsl:when test="@angle">
				<xsl:value-of select="@angle"/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="(@time + $popAdjust) * 360"/>
			</xsl:otherwise>
		</xsl:choose>
  	</xsl:variable>
  	<g transform="rotate({$angle})">
	   	<path d="M 0 {$bldgheight} L -{$bldgwidth div 2} -{$radius} L {$bldgwidth div 2} -{$radius} z" fill="{@color}" stroke="black" stroke-width="3" z-index="{$z}">
	   		<animateTransform attributeName="transform" attributeType="XML"
	                    type="translate" from="0,0" to="0,-{$bldgheight}" dur="{$popDuration}" begin="{$popTime}"
	                    additive="replace" fill="freeze"/>
	   	</path>
	</g>            
  </xsl:template>
  
</xsl:stylesheet>